Dim i As Integer, j As Integer, a As Integer, b As Integer, c As Variant, d As Variant, e As Variant, f As Variant, px As Variant, py As Variant, sqbufx As Integer, sqbufy As Integer, pos As Variant, found As Boolean, tries As Integer, try1 As Integer, direc As Integer
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If X < 4841.12 And Y < 4841.12 Then 'if the mousedown was in the correct area then find path
a = (X \ 242.56) 'set the labels to hold the x,y values
b = (Y \ 242.56)
lblx = "X:" & a
lbly = "Y:" & b
ReDim d(0 To 19, 0 To 19) 'set up data for finding the path
ReDim e(0 To 19, 0 To 19)
ReDim f(0 To 19, 0 To 19)
ReDim px(0 To 19, 0 To 19)
ReDim py(0 To 19, 0 To 19)
For i = 0 To 19
For j = 0 To 19
d(i, j) = c(i, j)
e(i, j) = 0
f(i, j) = 0
py(i, j) = 0
Next j
Next i
found = False
e(pos(0, 0), pos(0, 1)) = 1
f(a, b) = 1
tries = 0
top:
'the two following fors run whenever you click on the squares
'they basically do this:
'start with the goal square
'if the square next to me hasn't been reached yet then
'tell it that its been reached now
'and that it came from my direction(later, when the destination has been reached, it will use the direction data to retrace its steps)
'repeat for all sqaures until destination has been reached
For i = 0 To 19
For j = 0 To 19
If e(i, j) = 1 Then
On Error Resume Next
If d(i - 1, j) = 0 And e(i - 1, j) = 0 Then
e(i - 1, j) = 1
px(i - 1, j) = 1
py(i - 1, j) = j
End If
If d(i - 1, j - 1) = 0 And e(i - 1, j - 1) = 0 Then
e(i - 1, j - 1) = 1
px(i - 1, j - 1) = 2
py(i - 1, j - 1) = j
End If
If d(i - 1, j + 1) = 0 And e(i - 1, j + 1) = 0 Then
e(i - 1, j + 1) = 1
px(i - 1, j + 1) = 3
py(i - 1, j + 1) = j
End If
If d(i + 1, j) = 0 And e(i + 1, j) = 0 Then
e(i + 1, j) = 1
px(i + 1, j) = 4
py(i + 1, j) = j
End If
If d(i + 1, j - 1) = 0 And e(i + 1, j - 1) = 0 Then
e(i + 1, j - 1) = 1
px(i + 1, j - 1) = 5
py(i + 1, j - 1) = j
End If
If d(i + 1, j + 1) = 0 And e(i + 1, j + 1) = 0 Then